<ix-modal-header
  [requiredRoles]="requiredRoles"
  [title]="'SMB' | translate"
  [loading]="isFormLoading()"
></ix-modal-header>

<mat-card class="card">
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <ix-fieldset [title]="'NetBIOS' | translate">
        <ix-input
          formControlName="netbiosname"
          [label]="'NetBIOS Name' | translate"
          [tooltip]="tooltips.netbiosname | translate"
          [required]="true"
        ></ix-input>

        <ix-chips
          formControlName="netbiosalias"
          [label]="'NetBIOS Alias' | translate"
          [tooltip]="tooltips.netbiosalias | translate"
        ></ix-chips>

        <ix-input
          formControlName="workgroup"
          [label]="'Workgroup' | translate"
          [tooltip]="tooltips.workgroup | translate"
        ></ix-input>

        <ix-input
          formControlName="description"
          [label]="'Description' | translate"
          [tooltip]="tooltips.description | translate"
        ></ix-input>

        <ix-checkbox
          formControlName="enable_smb1"
          [label]="'Enable SMB1 support' | translate"
          [tooltip]="tooltips.enable_smb1 | translate"
        ></ix-checkbox>

        <ix-checkbox
          formControlName="ntlmv1_auth"
          [label]="'NTLMv1 Auth' | translate"
          [tooltip]="tooltips.ntlmv1_auth | translate"
        ></ix-checkbox>
      </ix-fieldset>

      @if (!isBasicMode) {
        <ix-fieldset [title]="'Other Options' | translate">
          <ix-select
            formControlName="unixcharset"
            [label]="'UNIX Charset' | translate"
            [tooltip]="tooltips.unixcharset | translate"
            [options]="unixCharsetOptions$"
          ></ix-select>

          <ix-select
            formControlName="encryption"
            [label]="'Transport Encryption Behavior' | translate"
            [options]="encryptionOptions$"
            [required]="true"
          ></ix-select>

          <ix-checkbox
            formControlName="debug"
            [label]="'Use Debug' | translate"
            [tooltip]="tooltips.debug | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="syslog"
            [label]="'Use Syslog Only' | translate"
            [tooltip]="tooltips.syslog | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="localmaster"
            [label]="'Local Master' | translate"
            [tooltip]="tooltips.localmaster | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="aapl_extensions"
            [label]="'Enable Apple SMB2/3 Protocol Extensions' | translate"
            [tooltip]="tooltips.aapl_extensions | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="multichannel"
            [label]="'Multichannel' | translate"
            [tooltip]="tooltips.multichannel | translate"
          ></ix-checkbox>

          <ix-combobox
            formControlName="admin_group"
            [label]="'Administrators Group' | translate"
            [tooltip]="tooltips.admin_group | translate"
            [provider]="adminGroupProvider"
          ></ix-combobox>

          <ix-select
            formControlName="guest"
            [label]="'Guest Account' | translate"
            [tooltip]="tooltips.guest | translate"
            [options]="guestAccountOptions$"
          ></ix-select>

          <ix-input
            formControlName="filemask"
            [label]="'File Mask' | translate"
            [tooltip]="tooltips.filemask | translate"
          ></ix-input>

          <ix-input
            formControlName="dirmask"
            [label]="'Directory Mask' | translate"
            [tooltip]="tooltips.dirmask | translate"
          ></ix-input>

          <ix-list
            formArrayName="bindip"
            [empty]="form.controls.bindip.controls.length === 0"
            [label]="'Bind IP Addresses' | translate"
            [tooltip]="tooltips.bindip | translate"
            (add)="addBindIp()"
          >
            @for (address of form.controls.bindip.controls; track address; let i = $index) {
              <ix-list-item
                [formGroupName]="i"
                (delete)="removeBindIp(i)"
              >
                <ix-select
                  formControlName="bindIp"
                  [label]="'IP Address' | translate"
                  [options]="bindIpAddressOptions$"
                  [required]="true"
                ></ix-select>
              </ix-list-item>
            }
          </ix-list>
        </ix-fieldset>
      }

      <ix-form-actions>
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isFormLoading()"
        >
          {{ 'Save' | translate }}
        </button>

        <button mat-button type="button" ixTest="toggle-advanced-settings" (click)="onAdvancedSettingsToggled()">
          {{
            isBasicMode
              ? ('Advanced Settings' | translate)
              : ('Basic Settings' | translate)
          }}
        </button>
      </ix-form-actions>
    </form>
  </mat-card-content>
</mat-card>
